package com.Exchanger;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Exchanger;

/**
 * Created by mike on 17/10/26.
 */
public class Runnable2 implements Runnable{
    private Exchanger<List<String>> exchanger;
    private List<String> changeList = new ArrayList<String>();
    public Runnable2(Exchanger exchanger){
        this.exchanger = exchanger;
    }
    @Override
    public void run() {
        for(int i=300;i<400;i++){
            changeList.add("String :"+i);
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {

            }
        }
        try {
            changeList = exchanger.exchange(changeList);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        for(String s : changeList){
            System.out.println("runnable2:"+s);
        }

    }
}
